<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Siteconfig_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	}
	
	function getAllConfig()
	{
		$query = $this->db->get('config');
		if ($query->num_rows() > 0)
		{
			$result = $query->result_array();
			foreach ($result as $row)
			{
				$result[$row['name']] = $row['value'];
			}            
			return $result;
		}
	}
	
	function saveconfig()
	{
		$this->db->set('value', $this->input->post('site_name'));
		$this->db->where('name', 'site_name');
		$this->db->update('config');
		
		
		$this->db->set('value', $this->input->post('site_close'));
		$this->db->where('name', 'site_close');
		$this->db->update('config');
		
		$this->db->set('value', $this->input->post('site_close_message'));
		$this->db->where('name', 'site_close_message');
		$this->db->update('config');
		
		$this->db->set('value', $this->input->post('site_email'));
		$this->db->where('name', 'site_email');
		$this->db->update('config');
		
				 
		$this->db->set('value', $this->input->post('site_copyright'));
		$this->db->where('name', 'site_copyright');
		$this->db->update('config');         
		
		$this->db->set('value', $this->input->post('site_keywords'));
		$this->db->where('name', 'site_keywords');
		$this->db->update('config');         
		
		$this->db->set('value', $this->input->post('site_description'));
		$this->db->where('name', 'site_description');
		$this->db->update('config');         
		
		$this->db->set('value', $this->input->post('diemdoc'));
		$this->db->where('name', 'diemdoc');
		$this->db->update('config');   
		
		$this->db->set('value', $this->input->post('diemgioithieu'));
		$this->db->where('name', 'diemgioithieu');
		$this->db->update('config');  
		
		$this->db->set('value', $this->input->post('diemdangkymoi'));
		$this->db->where('name', 'diemdangkymoi');
		$this->db->update('config'); 
		 
		$this->db->set('value', $this->input->post('user_reg'));
		$this->db->where('name', 'user_reg');
		$this->db->update('config');       
		
		$this->db->set('value', $this->input->post('user_active'));
		$this->db->where('name', 'user_active');
		$this->db->update('config');           
		
		$this->db->set('value', $this->input->post('binhluan'));
		$this->db->where('name', 'binhluan');
		$this->db->update('config');  
		
		$this->db->set('value', $this->input->post('binhchon'));
		$this->db->where('name', 'binhchon');
		$this->db->update('config');  
								  
		$this->db->set('value', $this->input->post('guilink'));
		$this->db->where('name', 'guilink');
		$this->db->update('config'); 
	
	} 
	
	function phpinfo_array ( $option = 1, $return = false )
	{
		global $sys_info;
		
		$pi = array();
		
			ob_start();
			phpinfo( $option );
			
			$info = preg_replace( array( 
				'#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', "#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%', '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', "# +#", '#<tr>#', '#</tr>#' 
			), array( 
				'$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%' 
			), ob_get_clean() );
			
			$sections = explode( '<h2>', strip_tags( $info, '<h2><th><td>' ) );
			unset( $sections[0] );
			
			foreach ( $sections as $section )
			{
				$n = substr( $section, 0, strpos( $section, '</h2>' ) );
				preg_match_all( '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', $section, $askapache, PREG_SET_ORDER );
				foreach ( $askapache as $m )
				{
					$pi[$n][$m[1]] = ( isset( $m[2] ) and ( ! isset( $m[3] ) || $m[2] == $m[3] ) ) ? $m[2] : array_slice( $m, 2 );
				}
			}
		
		
		
		return ( $return === false ) ? print_r( $pi ) : $pi;
	}           
}
?>
